//Tags: DP with DataStructure
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#define lowbit(x) (x & -x)

typedef long long ll;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 2e6 + 5;
int n, e_cnt, heads[N], t[N], a[N];
ll f[N], ans, val[N];

struct Edge {
  int v, nxt;
} e[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

inline void modify(int x, ll v) {
  while (x <= n) val[x] = std::max(val[x], v), x += lowbit(x);
}
inline ll query(int x) {
  ll res = 0;
  while (x) res = std::max(res, val[x]), x -= lowbit(x);
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("fullCombo.in", "r", stdin);
  freopen("fullCombo.out", "w", stdout);
#endif
#endif

  read(n);
  for (int i = 1; i <= n; ++i) read(t[i]), add(i + t[i], i);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= n; ++i) {
    for (int j = heads[i]; j; j = e[j].nxt) modify(e[j].v, f[e[j].v]);
    f[i] = ((i - t[i] > 0) ? query(i - t[i]) : 0) + (ll)t[i] * a[i];
    ans = std::max(ans, f[i]);
  }
  printf("%lld", ans);
  return 0;
}